/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler.action;

import com.funcom.peeler.peelable.PeelComponent;
import com.jmex.bui.BContainer;

public class ComponentStackChange implements Change {

    PeelComponent component;
    private int old_index;
    private int new_index;

    public ComponentStackChange( PeelComponent component, int old_index, int new_index ) {
        this.component = component;
        this.old_index = old_index;
        this.new_index = new_index;
    }

    public void startChange() {
    }

    public void endChange() {
    }

    public void doChange() {

        BContainer parent = component.getComponent().getParent();
        parent.remove( component.getComponent() );
        parent.add( new_index, component.getComponent(), component.getComponent().getBounds() );
    }

    public void undoChange() {

        BContainer parent = component.getComponent().getParent();
        parent.remove( component.getComponent() );
        parent.add( old_index, component.getComponent(), component.getComponent().getBounds() );
    }

    public boolean valid() {

        if ( old_index == new_index ) return false;

        return true;
    }
}
